package com.hippoDocker.feignhystrixorder.controller;

import com.hippoDocker.feignhystrixorder.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName PaymentController
 * @Description TODO OpenFeign测试
 * @Author hippoDocker
 * @Date 2022/6/15 10:36
 **/
@RestController
@RequestMapping("/payment/hystrix")
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
@Slf4j
public class OrderFeignController {
    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping("/ok/{id}")
    public String getPaymentById(@PathVariable("id") Integer id) {
        return paymentFeignService.paymentInfo_OK(id);
    }

    @GetMapping("/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHandler", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
//    })
//    @HystrixCommand
    public String paymentFeignTimeOut(@PathVariable("id") Integer id){
            return paymentFeignService.paymentInfo_Timeout(id);
    }

    // 定义熔断方法--超时或者异常调用
    public String paymentInfo_TimeoutHandler(Integer id) {
        return "我是消费者8000，对方支付系统繁忙请稍后再试，o(╥﹏╥)o";
    }

    //全局熔断方法
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试，o(╥﹏╥)o";
    }

}
